
<template>
	<view class="content">
		<form class="app-update-pv">
            <view
                    :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"88rpx"}'
                    class="cu-form-group">
                <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                      class="title">账户</view>
                <input   disabled
                         :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx"}'
                         :disabled="ro.username" type="text" v-model="ruleForm.username" placeholder="账户"></input>
            </view>
            <view
                    :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"88rpx"}'
                    class="cu-form-group">
                <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                      class="title">商家名称</view>
                <input   disabled
                         :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx"}'
                         :disabled="ro.shangjiaName" type="text" v-model="ruleForm.shangjiaName" placeholder="商家名称"></input>
            </view>
            <view
                    :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"88rpx"}'
                    class="cu-form-group">
                <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                      class="title">联系方式</view>
                <input   disabled
                         :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx"}'
                         :disabled="ro.shangjiaPhone" type="text" v-model="ruleForm.shangjiaPhone" placeholder="联系方式"></input>
            </view>
            <view
                    :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"88rpx"}'
                    class="cu-form-group">
                <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                      class="title">邮箱</view>
                <input   disabled
                         :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx"}'
                         :disabled="ro.shangjiaEmail" type="text" v-model="ruleForm.shangjiaEmail" placeholder="邮箱"></input>
            </view>
                <view
                        :style='{"boxShadow":"0 0 0px rgba(0,0,0,.3)","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(218, 220, 219, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"108rpx"}'
                        class="cu-form-group" @tap="shangjiaPhotoTap">
                    <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                          class="title">营业执照展示</view>
                    <view class="right-input" style="padding:0;textAlign:left">
                        <image
                                :style='{"width":"68rpx","boxShadow":"0 0 0px rgba(0,0,0,.3)","borderRadius":"100%","textAlign":"left","height":"68rpx"}'
                                class="avator" v-if="ruleForm.shangjiaPhoto" :src="ruleForm.shangjiaPhoto" mode="aspectFill">
                        </image>
                        <image  :style='{"width":"68rpx","boxShadow":"0 0 0px rgba(0,0,0,.3)","borderRadius":"100%","textAlign":"left","height":"68rpx"}'
                                class="avator" v-else src="../../static/gen/upload.png" mode="aspectFill"></image>
                    </view>
                </view>
			                <view :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"88rpx"}'
                      class="cu-form-group">
                    <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                          class="title">商家星级类型</view>
                    <picker @change="shangjiaXingjiTypesChange" :value="shangjiaXingjiTypesIndex" :range="shangjiaXingjiTypesOptions" range-key="indexName">
                        <view
                                :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx"}'
                                class="uni-input">{{ruleForm.shangjiaXingjiTypes?ruleForm.shangjiaXingjiValue:"请选择商家星级类型"}}</view>
                    </picker>
                </view>
<!-- text后缀 -->
            <view
                    :style='{"boxShadow":"0","backgroundColor":"rgba(255, 255, 255, 0.25)","borderColor":"rgba(228, 232, 230, 1)","margin":"0 0 0px 0","borderWidth":"2rpx","borderStyle":"none none solid none ","height":"210rpx"}'
                    class="cu-form-group">
                <view :style='{"width":"160rpx","fontSize":"28rpx","color":"#6a4826","textAlign":"left"}'
                      class="title">商家简介</view>
                <textarea :style='{"boxShadow":"0 0 0px rgba(0,0,0,.6) inset","backgroundColor":"rgba(255, 255, 255, 1)","borderColor":"#6a4826","borderRadius":"0px","color":"#6a4826","textAlign":"left","borderWidth":"0 0 6rpx","fontSize":"24rpx","borderStyle":"solid","height":"88rpx","height":"200rpx"}'
                          :disabled="ro.shangjiaContent" v-model="ruleForm.shangjiaContent" placeholder="商家简介"/>
            </view>

			<view class="btn">
				<button
					:style='{"boxShadow":"0 0 16rpx rgba(0,0,0,0) inset","backgroundColor":"#6a4826","borderColor":"#409EFF","borderRadius":"8rpx","color":"rgba(255, 255, 255, 1)","borderWidth":"0","width":"70%","fontSize":"32rpx","borderStyle":"solid","height":"80rpx"}'
					@tap="onSubmitTap" class="bg-red">提交</button>
			</view>
		</form>

					<w-picker mode="dateTime" step="1" :current="false" :hasSecond="false" @confirm="createTimeConfirm"
						  ref="createTime" themeColor="#333333"></w-picker>


	</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";

	export default {
		data() {
			return {
				cross: '',
                ro:{
					username: false,
					password: false,
					shangjiaName: false,
					shangjiaPhone: false,
					shangjiaEmail: false,
					shangjiaPhoto: false,
					shangjiaXingjiTypes: false,
					newMoney: false,
					shangjiaContent: false,
					shangjiaDelete: false,
					createTime: false,
				},
				ruleForm: {
					username: '',
					password: '',
					shangjiaName: '',
					shangjiaPhone: '',
					shangjiaEmail: '',
					shangjiaPhoto: '',
					shangjiaXingjiTypes: '',//数字
					shangjiaXingjiValue: '',//数字对应的值
					newMoney: '',
					shangjiaContent: '',
					shangjiaDelete: '',
					createTime: '',
				},
				// 登陆用户信息
				user: {},
				shangjiaXingjiTypesOptions: [],
				shangjiaXingjiTypesIndex : 0,

			}
		},
		components: {
			wPicker
		},
		computed: {
			baseUrl() {
				return this.$base.url;
			},
		},
		async onLoad(options) {

		/*下拉框*/
			let shangjiaXingjiTypesParams = {
				page: 1,
				limit: 100,
				dicCode: 'shangjia_xingji_types',
			}
			let shangjiaXingjiTypes = await this.$api.page(`dictionary`, shangjiaXingjiTypesParams);
			this.shangjiaXingjiTypesOptions = shangjiaXingjiTypes.data.list


			// 如果是更新操作
			if (options.id) {
				this.ruleForm.id = options.id;
				// 获取信息
				let res = await this.$api.info(`shangjia`, this.ruleForm.id);
				this.ruleForm = res.data;
			}
			if(options.shangjiaId){
                this.ruleForm.shangjiaId = options.shangjiaId;
			}
			// 跨表
			// this.styleChange()
		},
		methods: {
			// 下拉变化
            shangjiaXingjiTypesChange(e) {
            this.shangjiaXingjiTypesIndex = e.target.value
            this.ruleForm.shangjiaXingjiValue = this.shangjiaXingjiTypesOptions[this.shangjiaXingjiTypesIndex].indexName
            this.ruleForm.shangjiaXingjiTypes = this.shangjiaXingjiTypesOptions[this.shangjiaXingjiTypesIndex].codeIndex
        },


			// styleChange() {
			// 	this.$nextTick(() => {
			// 		// document.querySelectorAll('.app-update-pv .cu-form-group .uni-yaoxianStyle-yaoxianStyle').forEach(el=>{
			// 		//   el.style.backgroundColor = this.addUpdateForm.yaoxianStyle.content.backgroundColor
			// 		// })
			// 	})
			// },


			shangjiaPhotoTap() {
				let _this = this;
				this.$api.upload(function(res) {
					_this.ruleForm.shangjiaPhoto = _this.$base.url + 'upload/' + res.file;
					_this.$forceUpdate();
					_this.$nextTick(() => {
						// _this.styleChange()
					})
				});
			},
			// 日期控件
			createTimeConfirm(val) {
                console.log(val)
                this.ruleForm.createTime = val.result;
                this.$forceUpdate();
            },




			getUUID() {
				return new Date().getTime();
			},
			async onSubmitTap() {
				if ((!this.ruleForm.username)) {
					this.$utils.msg(`账户不能为空`);
					return
				}
				if ((!this.ruleForm.shangjiaName)) {
					this.$utils.msg(`商家名称不能为空`);
					return
				}
				if ((!this.ruleForm.shangjiaPhone) && (!this.$validate.isMobile(this.ruleForm.shangjiaPhone))) {
					this.$utils.msg(`联系方式不能为空并且需要输入正确格式`);
					return
				}
				if ((!this.ruleForm.shangjiaEmail) && (!this.$validate.isEmail(this.ruleForm.shangjiaEmail))) {
					this.$utils.msg(`邮箱不能为空并且需要输入正确格式`);
					return
				}
				if ((!this.ruleForm.shangjiaPhoto)) {
					this.$utils.msg(`营业执照展示不能为空`);
					return
				}
				if ((!this.ruleForm.shangjiaXingjiTypes)) {
					this.$utils.msg(`商家星级类型不能为空`);
					return
				}
				if (this.ruleForm.id) {
					await this.$api.update(`shangjia`, this.ruleForm);
				} else {
					await this.$api.save(`shangjia`, this.ruleForm);
				}
                uni.setStorageSync('pingluenStateState', true);
                this.$utils.msgBack('提交成功');
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			toggleTab(str) {
				this.$refs[str].show();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20upx;
	}

	.content:after {
		position: fixed;
		top: 0;
		right: 0;
		left: 0;
		bottom: 0;
		content: '';
		background-attachment: fixed;
		background-size: cover;
		background-position: center;
	}

	textarea {
		border: 1upx solid #EEEEEE;
		border-radius: 20upx;
		padding: 20upx;
	}

	.title {
		width: 180upx;
	}

	.avator {
		width: 150upx;
		height: 60upx;
	}

	.right-input {
		flex: 1;
		text-align: left;
		padding: 0 24upx;
	}

	.cu-form-group.active {
		justify-content: space-between;
	}

	.btn {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-wrap: wrap;
		padding: 20upx 0;
	}

	.cu-form-group {
		padding: 0 24upx;
		background-color: transparent;
		min-height: inherit;
	}

	.cu-form-group+.cu-form-group {
		border: 0;
	}

	.cu-form-group uni-input {
		padding: 0 30upx;
	}

	.uni-input {
		padding: 0 30upx;
	}

	.cu-form-group uni-textarea {
		padding: 30upx;
		margin: 0;
	}

	.cu-form-group uni-picker::after {
		line-height: 68rpx;
	}

	.select .uni-input {
		line-height: 68rpx;
	}

	.input .right-input {
		line-height: 68rpx;
	}
</style>